import socket

FILE_NAME = '/Users/sky/work/Others/Nothing/lotus.jpg'

client = socket.socket()
ip_port = ('127.0.0.1', 9999)
print("准备连接服务端")
client.connect(ip_port)
print("连接成功，准备发送文件")

# 打开文件，准备上传
with open(FILE_NAME, 'rb') as f:
    count = 0

    # 按每一段分割文件
    for i in f:
        client.send(i)
        count = count + 1

        # 等待接收完成
        data = client.recv(1024)
        print("count: %d, data: %s" % (count, data))
        # 判断服务器是否真正接收完成
        if data != b'success ACK':
            print('发送成功')
            break

# 发送结束符
client.send('EOF'.encode())
print('发送结束标志，退出')
